package com.lq.ecoldchain.ui.mine.verified

import android.content.Intent
import com.alibaba.android.arouter.facade.annotation.Route
import com.lq.ecoldchain.R
import com.lq.ecoldchain.base.BaseNavigator
import com.lq.ecoldchain.base.view.BaseActivity
import com.lq.ecoldchain.databinding.ActivityVerifiedBinding
import com.lq.ecoldchain.util.*
import kotlinx.android.synthetic.main.activity_verified.*
import org.kodein.di.Kodein
import org.kodein.di.generic.instance

/*
*2018/12/26 0026  19:27
*实名认证 by lq
*/
@Route(path = BaseNavigator.verified)
class VerifiedActivity : BaseActivity<ActivityVerifiedBinding>() {
    override val kodein = Kodein.lazy {
        extend(parentKodein)
        import(verfiedKodein)
    }

    private var isPositive = false
    override val layoutId = R.layout.activity_verified
    override val viewDelegate: VerifiedDelegate by instance()

    override fun initView() {
        binding.delegate = viewDelegate
        titleText("实名认证")
        idCardBackIv.setOnClickListener {
            isPositive = false
            PhotoShowUtils.choosePhoto(idCardBackIv)
        }
        idCardPositiveIv.setOnClickListener {
            isPositive = true
            PhotoShowUtils.choosePhoto(idCardPositiveIv)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            if (isPositive)
                CameraUtil.handlePhoto(requestCode, data?.data, idCardPositiveIv, object : QiNiuUtils.OnQiNiuListener {
                    override fun uploadSuccess(url: String) {
                        viewDelegate.viewModel.positive.value = url
                        logi { url }
                    }
                })
            else
                CameraUtil.handlePhoto(requestCode, data?.data, idCardBackIv, object : QiNiuUtils.OnQiNiuListener {
                    override fun uploadSuccess(url: String) {
                        viewDelegate.viewModel.back.value = url
                    }
                })
        }
    }

}